/**
 * 
 */
package infrastructure;

import java.io.IOException;

import org.apache.log4j.*;




/**
 * @author Danielondon
 *
 */
public final class LoggingManager {
	
	private static Logger singletonLogger;
	
	private LoggingManager(){
		
	}
	
	public static Logger getLogger(){
		if (singletonLogger == null){		
			singletonLogger = CreateLogger("logs/protein_prediction_weka.log");
		}
		
		return singletonLogger;
	}
	
	private static Logger CreateLogger(String filePath)
	{
		// initialize logger
		Logger logger = Logger.getRootLogger();
		String logDir = filePath;
		//String pattern = "%d{ISO8601} %-5p [%t] %c: %m%n";
		String pattern = "%d{ISO8601} %p [%t] %c (%F:%L) - %m%n";
		PatternLayout pLayout = new PatternLayout(pattern);
		FileAppender fa = null;
		try {
			fa = new FileAppender(pLayout, logDir, true );
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.addAppender(fa);
		logger.setLevel(Level.ALL);
		return logger;
	}	
	
	public static void SetLoggerLevel(String newLevel)
	{
		Level level = Level.toLevel(newLevel);
		singletonLogger.setLevel(level);
	}
}
